home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / hard / drivr / serpat20.lha / ParallelPatch.asm < prev    next >
Assembly Source File  |  1992-10-01  |  12KB  |  327 lines

  1. ;****** Auto-Revision Header (do not edit) *******************************
  2. ;*
  3. ;* © Copyright by PetiWare
  4. ;*
  5. ;* Filename         : ParallelPatch.asm
  6. ;* Created on       : 24-Aug-92
  7. ;* Created by       : Peter Simons
  8. ;* Current revision : V2.001
  9. ;*
  10. ;*
  11. ;* Purpose: Patches the OpenDevice()-Routine to use any device instead
  12. ;*          of the serial.
  13. ;*
  14. ;*
  15. ;* V2.001 : changed patch-id
  16. ;*
  17. ;* V2.000 : Released:                           Peter Simons (24-Aug-92)
  18. ;*
  19. ;* V1.003 : added a delay before releasing the memory of NewOpenDev(),
  20. ;*          because this could cause problems, when the routine is in
  21. ;*          use, while the patch is removed.
  22. ;*
  23. ;* V1.002 : NewUnit-switch added
  24. ;*
  25. ;* V1.001 : PatchOnlyUnit-switch added
  26. ;*
  27. ;* V1.000 : released:                           Peter Simons (24-Aug-92)
  28. ;*
  29. ;* V0.300 : Argument-Parsing implemented
  30. ;*
  31. ;* V0.200 : Main patch-routine works
  32. ;*
  33. ;* V0.100 : Patch based on my CPUClear V2.011
  34. ;*
  35. ;* V0.000 : --- Initial release ---
  36. ;*
  37. ;*************************************************************************
  38. ;
  39. ;
  40.  
  41. ;***************************************************************************
  42. ;*                                                                         *
  43. ;* SEKTION: Labels, Macros, Switches, Structures                           *
  44. ;*                                                                         *
  45. ;***************************************************************************
  46.  
  47. ;-------------------------------------- Switches -----------
  48.                 MC68000
  49.                 EXEOBJ
  50.                 OBJFILE "RAM:ParallelPatch"
  51.                 NEWSYNTAX
  52.                 MULTIPASS
  53.  
  54. ;-------------------------------------- Exec ---------------
  55. MEMF_PUBLIC     equ     1<<0
  56.  
  57. ;-------------------------------------- Labels -------------
  58.                 MACLIB  "DATAS:Offsets.preass"
  59. KICKVERSION     equ     37
  60.  
  61. _DOSBase        equr    A5
  62. _NewOpenDev     equr    A3
  63. _OutputHandle   equr    D7
  64. _RDArgsStruct   equr    D6
  65.  
  66. ;-------------------------------------- Macros -------------
  67. REVISION        MACRO
  68.                 dc.b "2.001"
  69.                 ENDM
  70. REVDATE         MACRO
  71.                 dc.b "05-Sep-92"
  72.                 ENDM
  73.  
  74.  
  75.  
  76. ;***************************************************************************
  77. ;*                                                                         *
  78. ;* SEKTION: Program                                                        *
  79. ;*                                                                         *
  80. ;***************************************************************************
  81.  
  82. START:          lea     (DATA,PC),a4
  83.                 BASEREG A4,DATA
  84.                 OPTIMON BASEREG
  85.  
  86.                 move.l  ($4).W,a6
  87.                 lea     (dosname,PC),a1
  88.                 moveq   #KICKVERSION,d0
  89.                 jsr     (_LVOOpenLibrary,a6)            ; open Dos-Library
  90.                 tst.l   d0
  91.                 beq     .ErrorExit
  92.                 move.l  d0,_DOSBase
  93.  
  94.                 move.l  _DOSBase,a6
  95.                 lea     (Template,PC),a0
  96.                 move.l  a0,d1
  97.                 lea     (_NewDeviceName,PC),a2
  98.                 move.l  a2,d2
  99.                 moveq   #0,d3
  100.                 jsr     (_LVOReadArgs,a6)
  101.                 move.l  d0,_RDArgsStruct
  102.                 bne.b   .ArgsOkay
  103.                 pea     (.CloseDosLib,PC)
  104.                 bra     _ErrorHandle
  105.  
  106. .ArgsOkay       move.l  _DOSBase,a6
  107.                 jsr     (_LVOOutput,a6)                 ; get standard-
  108.                 move.l  d0,_OutputHandle                ; outputhandle
  109.  
  110.                 move.l  _OutputHandle,d1
  111.                 beq.b   .SkipWrite
  112.                 lea     (Header,PC),a0                  ; write standard-
  113.                 move.l  a0,d2                           ; header
  114.                 moveq   #Header_len,d3
  115.                 jsr     (_LVOWrite,a6)
  116.  
  117. .SkipWrite      move.l  ($4).w,a6
  118.                 move.l  (_LVOOpenDevice+2,a6),_NewOpenDev ; is the patch
  119.                 cmp.l   #'PPAT',(new_ID,_NewOpenDev)    ; already installed?
  120.                 beq     .RemovePatch                    ; Yep->remove
  121.  
  122. ;-------------------------------------- install patch ------
  123.  
  124.                 lea     (_NewDeviceName,PC),a0
  125.                 tst.l   (a0)
  126.                 bne.b   .ArgOkay
  127.                 moveq   #116,d0         ; REQUIRED_AGUMENT_MISSING
  128.                 pea     (.FreeArgs,PC)
  129.                 bra     _PrintError
  130.  
  131. .ArgOkay        move.l  (a0),a0
  132.                 bsr     _Len
  133.                 add.l   #NewOpenDev_len,d0
  134.                 moveq   #MEMF_PUBLIC,d1
  135.                 move.l  ($4).W,a6
  136.                 jsr     (_LVOAllocVec,a6)
  137.                 tst.l   d0
  138.                 bne.b   .BufferOkay
  139.                 pea     (.FreeArgs,PC)
  140.                 moveq   #103,d0                 ; NO_FREE_STORE
  141.                 bra     _PrintError
  142.  
  143. .BufferOkay     move.l  d0,_NewOpenDev
  144.                 lea     (NewOpenDev,PC),a0
  145.                 move.l  _NewOpenDev,a1          ; copy patch into
  146.                 moveq   #NewOpenDev_len,d0      ; reserved buffer
  147.                 jsr     (_LVOCopyMem,a6)
  148.  
  149.                 tst.l   (_PatchOnlyUnit)
  150.                 beq.b   .NoOnlyUnit
  151.                 move.l  (_PatchOnlyUnit,PC),a0
  152.                 move.l  (a0),(new_PatchOnlyUnit,_NewOpenDev)
  153.  
  154. .NoOnlyUnit     tst.l   (_NewUnit)
  155.                 beq.b   .NoNewUnit
  156.                 move.l  (_NewUnit,PC),a0
  157.                 move.l  (a0),(new_NewUnit,_NewOpenDev)
  158.  
  159. .NoNewUnit      move.l  (_NewDeviceName,PC),a0
  160.                 bsr     _Len
  161.                 lea     (new_NewDevName,_NewOpenDev),a1 ; copy new device-
  162.                 jsr     (_LVOCopyMem,a6)                ; name into reserved
  163.                                                         ; buffer
  164.                 jsr     (_LVOForbid,a6)
  165.                 move.l  ($4).w,a1
  166.                 move.w  #_LVOOpenDevice,a0              ; patch OS-function
  167.                 move.l  _NewOpenDev,d0
  168.                 jsr     (_LVOSetFunction,a6)
  169.                 move.l  d0,(new_OldOpenDev,_NewOpenDev) ; save old vector
  170.                 jsr     (_LVOCacheClearU,a6)            ; flush caches for
  171.                 jsr     (_LVOPermit,a6)                 ; '40 compatiblity
  172.  
  173.                 lea     (Install,PC),a0                 ; give feedback :-)
  174.                 moveq   #Install_len,d3
  175.                 bra.b   .exit
  176.  
  177. ;-------------------------------------- remove patch -------
  178. .RemovePatch    move.l  ($4).w,a1
  179.                 move.w  #_LVOOpenDevice,a0
  180.                 move.l  (new_OldOpenDev,_NewOpenDev),d0
  181.                 move.l  ($4).W,a6
  182.                 jsr     (_LVOSetFunction,a6)            ; replace old
  183.                 move.l  d0,a2                           ; function and
  184.                                                         ; release memory
  185.                 move.l  _DOSBase,a6                     ; after a delay
  186.                 moveq   #100,d1
  187.                 jsr     (_LVODelay,a6)
  188.  
  189.                 move.l  a2,a1
  190.                 move.l  ($4).W,a6
  191.                 jsr     (_LVOFreeVec,a6)
  192.  
  193.                 move.l  _DOSBase,a6
  194.                 lea     (Remove,PC),a0
  195.                 moveq   #Remove_len,d3
  196.  
  197. ;-------------------------------------- exit gracefully ----
  198.  
  199. .exit           move.l  _OutputHandle,d1
  200.                 beq.b   .FreeArgs
  201.                 move.l  a0,d2
  202.                 move.l  _DOSBase,a6
  203.                 jsr     (_LVOWrite,a6)
  204.  
  205.                 move.l  _OutputHandle,d1
  206.                 lea     (Returns,PC),a0
  207.                 move.l  a0,d2
  208.                 moveq   #Returns_len,d3
  209.                 jsr     (_LVOWrite,a6)
  210.  
  211. .FreeArgs       move.l  _RDArgsStruct,d1
  212.                 move.l  _DOSBase,a6
  213.                 jsr     (_LVOFreeArgs,a6)
  214.  
  215. .CloseDosLib    move.l  ($4).W,a6               ; close resources
  216.                 move.l  _DOSBase,a1
  217.                 jsr     (_LVOCloseLibrary,a6)
  218.  
  219. .ErrorExit      moveq   #0,d0
  220.                 rts
  221.  
  222. ;***************************************************************************
  223. ;*                                                                         *
  224. ;* SEKTION: Subroutines                                                    *
  225. ;*                                                                         *
  226. ;***************************************************************************
  227. _ErrorHandle:   move.l  _DOSBase,a6
  228.                 jsr     (_LVOIoErr,a6)
  229. _PrintError:    move.l  d0,d1
  230.                 moveq   #0,d2
  231.                 move.l  _DOSBase,a6
  232.                 jmp     (_LVOPrintFault,a6)
  233.  
  234.  
  235. _Len:           pea     (a0)            ; save register
  236. .loop           tst.b   (a0)+
  237.                 bne.b   .loop           ; currect char equal zero?
  238.                 move.l  a0,d0
  239.                 move.l  (SP)+,a0
  240.                 sub.l   a0,d0           ; return string-length INCLUDING
  241.                 rts                     ; the ZERO-byte
  242.  
  243.  
  244. ;***************************************************************************
  245. ;*                                                                         *
  246. ;* SEKTION: new OpenDev()-Routine                                          *
  247. ;*                                                                         *
  248. ;***************************************************************************
  249. NewOpenDev:
  250. saveregs        setrl   a0-a1
  251.                 movem.l saveregs,-(SP)
  252.  
  253.                 lea     (.PatchOnlyUnit,PC),a1
  254.                 cmp.w   #-1,(a1)
  255.                 beq.b   .Cmp
  256.                 cmp.l   (a1),d0
  257.                 bne.b   .OpenNormal
  258.  
  259. .Cmp            lea     (.SerDeviceName,PC),a1
  260. .CmpLoop        tst.b   (a0)                    ; compare device-name with
  261.                 beq.b   .PatchIt                ; the specified one (default
  262.                 cmpm.b  (a0)+,(a1)+             ; is serial.device) and
  263.                 bne.b   .OpenNormal             ; replace it if it's the
  264.                 bra.b   .CmpLoop                ; same
  265.  
  266. .PatchIt        lea     (.NewUnit,PC),a0
  267.                 cmp.l   #-1,(a0)
  268.                 beq.b   .NoNewUnit
  269.  
  270.                 movem.l (SP)+,saveregs
  271.                 lea     (.NewDeviceName,PC),a0
  272.                 move.l  (.NewUnit,PC),d0
  273.                 bra.b   .OldOpenDev
  274.  
  275. .NoNewUnit      movem.l (SP)+,saveregs
  276.                 lea     (.NewDeviceName,PC),a0
  277.                 bra.b   .OldOpenDev
  278.  
  279. .OpenNormal     movem.l (SP)+,saveregs
  280.  
  281. new_OldOpenDev  equ     (*-NewOpenDev+2)
  282. .OldOpenDev     jmp     ($00000000).L
  283. new_ID          equ     (*-NewOpenDev)
  284.                 dc.b    "PPAT"
  285. new_PatchOnlyUnit       equ     (*-NewOpenDev)
  286. .PatchOnlyUnit  dc.l    -1
  287. new_NewUnit     equ     (*-NewOpenDev)
  288. .NewUnit        dc.l    -1
  289. .SerDeviceName  dc.b    "parallel.device",0
  290. new_NewDevName  equ     (*-NewOpenDev)
  291. .NewDeviceName
  292.  
  293. NewOpenDev_len  equ     (*-NewOpenDev)          ; length of routine
  294.  
  295. ;***************************************************************************
  296. ;*                                                                         *
  297. ;* SEKTION: Daten, Zeiger                                                  *
  298. ;*                                                                         *
  299. ;***************************************************************************
  300. DATA:
  301.  
  302. dosname         dc.b    "dos.library",0
  303. Header          dc.b    $9B,"1;33",$6D
  304.                 dc.b    "$VER: ParallelPatch "
  305.                 REVISION
  306.                 dc.b    " ("
  307.                 REVDATE
  308.                 dc.b    ")"
  309.                 dc.b    $9B,$6D
  310.                 dc.b    " coding by Peter Simons",$0A
  311. Header_len      equ     (*-Header)
  312.  
  313. Install         dc.b    "Installed"
  314. Install_len     equ     (*-Install)
  315. Remove          dc.b    "Removed"
  316. Remove_len      equ     (*-Remove)
  317. Returns         dc.b    "...",$0A,$0A
  318. Returns_len     equ     (*-Returns)
  319.  
  320. Template        dc.b    "NewDevice,POU=PatchOnlyUnit/N,NewUnit/N",0
  321.  
  322. _NewDeviceName  ds.l    1
  323. _PatchOnlyUnit  ds.l    1
  324. _NewUnit        ds.l    1
  325.  
  326.                 END
  327.